//This is a fork of a userscript from https://github.com/MaresOnMyFace/flag-hider
//Apart from EQG Flags, Ive included TFH Flags, as well G5 Flags
//This serves as a joint solution with https://ponepaste.org/4869 (Flag Filter for 4ChanX)
//Friendship is Magic
// ==UserScript==
// @name     flag hider2
// @version  6
// @grant    none
// @author       (You)
// @match        *://boards.4channel.org/mlp*
// @run-at       document-start
// ==/UserScript==

var bad_flag_classes =
    [
     	 "bfl-eqs",
     	 "bfl-eqt",
         "bfl-son",
         "bfl-ada",
         "bfl-ab",
         "bfl-eqa",
         "bfl-eqf",
         "bfl-eqp",
         "bfl-eqr",
         "bfl-eqi",
         "bfl-era",
         "bfl-tp",
         "bfl-tfv",
         "bfl-tft",
         "bfl-tfs",
         "bfl-tfp",
         "bfl-tfo",
         "bfl-tfa",
         "bfl-ss",
         "bfl-pp",
         "bfl-iz",
    ];

function checkAndDeleteAll() {
    bad_flag_classes.map(evil => document.getElementsByClassName(evil)).forEach(function(els) {while (els.length>0) {els[0].remove()};});
}
function checkAndDeleteSingle(n) {
    if (bad_flag_classes.some(function(evil) {return n.classList.contains(evil);})) {
        n.remove();
    }
}

function installMutationObserver(root) {
    if (!("MutationObserver" in window)) {
        window.MutationObserver = window.WebKitMutationObserver || window.MozMutationObserver;
    }
    var observer = new MutationObserver(function (mutations) {
        mutations.forEach(function(m) {
            m.addedNodes.forEach(function(n){
                if(n.tagName == "SPAN") {
                    checkAndDeleteSingle(n);
                }
            });
        });
    });
    observer.observe(root, {childList: true, subtree: true, attributes: true});
}
function installStupidObserver(dbUtilsProm,root) {
    if (!("MutationObserver" in window)) {
        window.MutationObserver = window.WebKitMutationObserver || window.MozMutationObserver;
    }
    var observer = new MutationObserver(function (mutations) {
        mutations.forEach(function(m) {
            m.addedNodes.forEach(function(n){if(n.tagName == "DIV") {
                    n.querySelectorAll("span").forEach(function(node) {checkAndDeleteSingle(node);});
                }
            });
        });
    });
    observer.observe(document, {childList: true, subtree: true, attributes: true});
}

//dom parser
checkAndDeleteAll();
//4chan x
installMutationObserver(document);
//4chan native
window.setTimeout(function() { installStupidObserver(); }, 100);